import 'dart:convert';

import 'package:situation/data/request/base_request.dart';
import 'package:situation/domain/common/server_config.dart';
import 'package:situation/shared/constant/app_constant.dart';
import 'package:situation/shared/shared.dart';
import 'package:get/get.dart';

class ServerUrlStore extends GetxController {
  static ServerUrlStore get to => Get.find();

  List<ServerConfig> _config = [
    ServerConfig(
      name: "正式",
      intercom_url: "192.168.1.22",
      server_url: "https://api.sxmbxt.com/",
    ),
    ServerConfig(
      name: "本地",
      intercom_url: "192.168.1.22",
      server_url: "https://api.sxmbxt.com/",
    ),
  ];
  int configIndex = 0;

  List<ServerConfig> getConfigList() {
    return _config;
  }

  @override
  Future<void> onInit() async {
    super.onInit();
    UtilSp.putString(AppConstant.serverUrlConfig, json.encode(_config));
    UtilSp.putInt(AppConstant.serverUrlConfigId, configIndex);
  }



  getCurrentConfig() {
    configIndex = UtilSp.getInt(AppConstant.serverUrlConfigId)!;
    return _config[configIndex];
  }
}
